﻿// 1.1.7.04. Write a program, which finds the maximal sequence of consecutive equal elements in an array.
// E.g.: {1, 1, 2, 3, 2, 2, 2, 1} -> {2, 2, 2}.

using System;

class SequenceOfContiguesEqualElements
{
    static void Main()
    {
        int[] someArray = new int[] { 2, 1, 1, 2, 3, 3, 2, 2, 2, 1 };
        int equalElementsCounter = 1;
        int equalElementValue = 0;
        int bestEqualElementsCounter = 1;
        int bestEqualElementValue = 0;

        for (int i = 1; i < someArray.Length; i++)
        {
            if (someArray[i] == someArray[i - 1])
            {
                equalElementsCounter++;
                equalElementValue = someArray[i];
                if (equalElementsCounter > bestEqualElementsCounter)
                {
                    bestEqualElementsCounter = equalElementsCounter;
                    bestEqualElementValue = equalElementValue;
                }
            }
            else
            {
                equalElementsCounter = 1;
            }
        }

        Console.Write("{");
        for (int i = 0; i < bestEqualElementsCounter; i++)
        {
            if (i != bestEqualElementsCounter - 1)
            {
                Console.Write(bestEqualElementValue + ",");
            }
            else
            {
                Console.Write(bestEqualElementValue);
            }
        }
        Console.WriteLine("}");
    }
}